import java.io.Serializable;
import java.util.Arrays;
import java.util.HashSet;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class T2 {
    public static void main(String[] args) {
        A a = new A();
        Thread t1 = new Thread(a, "线程一");
        Thread t2 = new Thread(a, "线程二");
        t1.start();
        t2.start();
    }
}

class A implements Runnable {
    int i = 1;
    char[] c = new char[26];
    Object obj = new Object();

    @Override
    public void run() {
        while (true) {
            synchronized (obj) {
                obj.notifyAll();
                if (i > 100) {
                    break;
                }
                System.out.println(Thread.currentThread().getName() + ":" + i);
                i++;
                try {
                    obj.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }

    }

}

/**
 * 线程：t1、t2
 * t1线程拿到同步锁，开始执行同步代码块
 * t1线程唤醒所有线程,因为t1线程有对象锁，所以t2线程要等待t1线程释放对象锁才能执行同步代码块
 * 判断(跳出循环的语句)
 * t1线程打印输出语句
 * t1线程调用wait方法释放对象锁进入等待状态
 * 继续循环
 * <p>
 * <p>
 * t2线程拿到同步锁，开始执行同步代码块
 * t2线程唤醒所有线程
 * 判断(跳出循环的语句)
 * t2线程打印输出语句
 * t2线程调用wait方法释放对象锁进入等待状态
 * 继续循环
 */











